import os
import shutil

# 转化EC图片名称
def generate_new_name(root_dir):
    for date_folder in os.listdir(root_dir):
        if date_folder == ".DS_Store":
            continue
        date_path = os.path.join(root_dir, date_folder)
        for file in os.listdir(date_path):
            if file == ".DS_Store":
                continue
            parts = file.split('_')
            new_filename = f'ECRAIN24{parts[0] + parts[1]}'
            old_file_path = os.path.join(date_path, file)
            new_filename_path = os.path.join(date_path, new_filename)
            print(old_file_path, new_filename_path)
            os.rename(old_file_path, new_filename_path)


def copy_files_to_folder(src_root, dest_folder):
    # 确保目标文件夹存在
    if not os.path.exists(dest_folder):
        os.makedirs(dest_folder)

    # 遍历源目录及其子目录
    for root, dirs, files in os.walk(src_root):
        for file in files:
            src_file_path = os.path.join(root, file)
            dest_file_path = os.path.join(dest_folder, file)

            # 复制文件
            shutil.copy2(src_file_path, dest_file_path)
            print(f"Copied {src_file_path} to {dest_file_path}")
if __name__ == '__main__':
    path = "/Users/luofan/Desktop/pic2"
    copy_files_to_folder(path, "/Users/luofan/Desktop/pic")
    # generate_new_name(path)
